package com.aaa.service.scl.Impl;

import com.aaa.dao.scl.SclPlaneDao;
import com.aaa.entity.MyPage;
import com.aaa.entity.scl.Scl;
import com.aaa.entity.scl.SclPlane;
import com.aaa.service.scl.SclPlaneService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * (SclPlane)表服务实现类
 *
 * @author makejava
 * @since 2022-10-27 19:11:05
 */
@Service
public class SclPlaneServiceImpl implements SclPlaneService {
   @Autowired
   private SclPlaneDao sclPlaneDao;

   /**
    * 查询所有计划
    * @param myPage
    * @return
    */
   @Override
   public List<SclPlane> queryAll(MyPage myPage) {
      PageHelper.startPage(myPage.getPage(),myPage.getLimit());
      List<SclPlane> sclPlanes = sclPlaneDao.selectAllData();
      return sclPlanes;
   }

   /**
    *查询邀请码
    * @param plane
    * @return
    */
   @Override
   public boolean selectPlane(SclPlane plane) {
      List<SclPlane> select = sclPlaneDao.select(plane);
      return select.size()==0;
   }

   /**
    * 添加计划 、修改计划
    * @param sclPlane
    * @return
    */
   @Override
   public boolean insertPlane(SclPlane sclPlane, HttpSession session) {
      //获取创建人的id 从session中获取
      Integer login1 = (Integer) session.getAttribute("login1");
      System.out.println("login1 = " + login1);
      sclPlane.setUid(login1);
      int insert;
      //判断id是否为空
      if (sclPlane.getId() == null){
         //为空添加 返回true
         insert = sclPlaneDao.insertPlane(sclPlane);
         return true;
      }else{
         //不为空修改  返回true
         insert = sclPlaneDao.updatePlane(sclPlane);
         return true;
      }
   }

   /**
    *获取邀请码
    * @param sclPlane
    * @return
    */
   @Override
   public SclPlane queryByQyCode(SclPlane sclPlane) {
      SclPlane sclPlane1 = sclPlaneDao.selectOne(sclPlane);
      return sclPlane1;
   }

   /**
    * 模糊查询
    * @param myPage
    * @param sclPlane
    * @return
    */
   @Override
   public PageInfo<SclPlane> querysclAll(MyPage myPage, SclPlane sclPlane) {
      PageHelper.startPage(myPage.getPage(), myPage.getLimit());
      List<Scl> scls = sclPlaneDao.querysclAll(sclPlane);
      return new PageInfo(scls);
   }
}

